package net.begincode.SSO.filter;

import java.io.IOException;
import java.util.Properties;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;

import net.begincode.SSO.util.ConfigFileUtil;

/**
 * 注销
 * @author 遗忘
 * @date 2017.6.2
 */
public class LogoutFilter implements Filter {
	private static final String SSO_LOGOUT_URL = "http://localhost:8080/SSO-web/user/logout.htm";
	private String ssoLogoutURL; //统一注销地址
	@Override
	public void init(FilterConfig filterConfig) throws ServletException {

	}

	@Override
	public void doFilter(ServletRequest sRequest, ServletResponse sResponse, FilterChain chain)
			throws IOException, ServletException {
		HttpServletResponse response = (HttpServletResponse) sResponse;
		Properties properties = ConfigFileUtil.getProperties(this.getClass(), "URLConfig.properties");
		if(properties.isEmpty()||properties.getProperty("SSO_LOGOUT_URL")==null){
			ssoLogoutURL = SSO_LOGOUT_URL;
		}else{
			ssoLogoutURL = properties.getProperty("SSO_LOGOUT_URL");
		}
		response.sendRedirect(ssoLogoutURL);
		return;
	}

	@Override
	public void destroy() {

	}

}
